package com.homwee.factory;

import android.content.Context;
import android.graphics.PixelFormat;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Gravity;
import android.view.WindowManager;
import android.widget.LinearLayout;


public class SystemMenu extends LinearLayout{

	private boolean isShow =false;
	public int screenWidth =0;
	public int screenHeigth =0;
	private WindowManager mWm ;
	private WindowManager.LayoutParams layoutparams;
	
	public SystemMenu(Context context) {
		super(context);
		// TODO Auto-generated constructor stub
		init();
	}
	
	private void init(){
		setOrientation(VERTICAL);
		mWm = (WindowManager)getContext().getSystemService(Context.WINDOW_SERVICE);
		
		DisplayMetrics outMetrics=new DisplayMetrics();
		mWm.getDefaultDisplay().getMetrics(outMetrics);
		screenWidth=outMetrics.widthPixels;
		screenHeigth=outMetrics.heightPixels;
		layoutparams = new WindowManager.LayoutParams(); 
        layoutparams.format = PixelFormat.TRANSLUCENT;
        layoutparams.flags=WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL| WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
		layoutparams.type = WindowManager.LayoutParams.TYPE_SYSTEM_ALERT;
		layoutparams.gravity = Gravity.RIGHT|Gravity.TOP;
                layoutparams.width = 200;//WindowManager.LayoutParams.WRAP_CONTENT;
                layoutparams.height = 60;//WindowManager.LayoutParams.WRAP_CONTENT;
	}
	public void show(){
		if(isShow ==false){
			mWm.addView(this, layoutparams);
			isShow =true;
		}
	}
	
	public void hide(){
		if(isShow ==true){
			mWm.removeView(this);
			isShow =false;
		}
	}
	
	public void removeMenu(){
		if(isShow ==true){
			mWm.removeView(this);
			isShow =false;
		}
	}
	
	public boolean isShow(){
		return isShow;
	}
}